package com.controller;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.RequestDispatcher;
import com.model.Guess;
import java.sql.SQLException;
import java.util.List;
import java.util.ArrayList;
import com.service.UserService;

public class SportsController extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {

        List<Guess> sportsList = new ArrayList<Guess>();

        try {

            UserService userService = new UserService();

            userService.setConnection();

            List<Guess> list = userService.getAllGuess();

            for (int i = 0; i < list.size(); i++) {

                Guess guess = list.get(i);

                if (guess.getGuessCategory().equalsIgnoreCase("sports")) {

                    sportsList.add(guess);

                }


            }

            userService.closeConnection();

            request.setAttribute("sportsList", sportsList);
            RequestDispatcher requestDispatcher = request.getRequestDispatcher("/sports.jsp");
            requestDispatcher.forward(request, response);




        } catch (ClassNotFoundException ex) {
            ex.printStackTrace();
        } catch (SQLException ex) {
            ex.printStackTrace();
        }






    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
    }
}
